<script>
	import config from './config'
	import store from '@/store'
	import constant from './utils/constant.js';

	import Vue from 'vue'
import { getWebsiteConfig } from './api/system/system';
	export default {
		data() {
			return {
				preferences: null, // 偏好设置，map对象
			}
		},
		onLaunch: function() {
			this.initApp();
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight + 4;
					// #endif		

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		// onHide: function() {
		// 	console.log('App Hide')
		// },
		methods: {
			initApp() {
				var that = this;
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				this.checkLogin();
				// 设置黑色主题 true / false
				// this.$tm.theme.setBlack(false); 
				// 获取位置（百度sdk）
				// #ifdef APP-PLUS
				// setTimeout(() => {
				// 	that.$loc.getlocation().then(res => {
				// 		console.log('获取位置成功')
				// 		const location_info = {
				// 			lat: res.latitude,
				// 			lng: res.longitude,
				// 			address: res.address
				// 		}
				// 		uni.setStorageSync(constant.location, location_info);
				// 	}).catch(err => {
				// 		console.log('获取位置失败: ')
				// 		console.log(err)
				// 	})
				// }, 1000)
				// #endif
			},
			initConfig() {
				this.globalData.config = config;
				uni.getStorage({
					key: constant.preferences.preferences,
					fail() {
						uni.setStorageSync(constant.preferences.preferences, config.preferences)
					}
				})
			},
			checkLogin() {
				// 从缓存查询
				const loginUser = uni.getStorageSync(constant.user);
				if (loginUser) {
					this.$store.state['modules/user'].user = loginUser;
					this.$store.state['modules/user'].nickname = loginUser.nickname
					// 跳转
					// this.$tab.reLaunch('/pages/index')
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "colorui/icon.css";
	@import "uview-ui/index.scss";
	@import "./static/scss/index.scss";
	/* 每个页面公共css */
	@import "./tm-vuetify/mian.min.css";
	@import "./tm-vuetify/scss/theme.css";

	page {
		background: linear-gradient(200deg, #e3c5eb, #a9c1ed);
	}
</style>